package org.zf.database.consts;

import cn.hutool.core.bean.BeanException;
import cn.hutool.core.util.EnumUtil;
import lombok.Getter;

import java.util.Map;

/**
 * @author Admin
 * @version 1.0
 * @description: 数据库权限类型
 * @date 2021/9/14 14:42
 */
@Getter
public enum DBPrivsType
{
    SELECT("SELECT", "查询"),
    INSERT("INSERT", "插入"),
    UPDATE("UPDATE", "更新"),
    DELETE("DELETE", "删除"),
    TRUNCATE("TRUNCATE", "清空表"),
    DROP("DROP", "删除表"),
    CREATE("CREATE", "创建表");

    private final String priv;
    private final String label;

    DBPrivsType(String priv, String label)
    {
        this.priv = priv;
        this.label = label;
    }

    public static DBPrivsType parsePrivs(String privs) throws RuntimeException
    {
        Map<String, DBPrivsType> enumMap = EnumUtil.getEnumMap(DBPrivsType.class);
        for (DBPrivsType value : enumMap.values())
        {
            if (value.getPriv().equalsIgnoreCase(privs))
                return value;
        }
        throw new BeanException("不支持的数据库权限类型：" + privs);
    }
}
